package com.esteel.settlement.config.validator;

import java.util.Set;

import javax.validation.ConstraintViolation;

/**
 * 报文验证的结果类
 * @author zhangxiuzhi
 *
 */
public class ValidatorResult<T> {
	
	private boolean isValid=false;
	private Set<ConstraintViolation<T>> set;

	public ValidatorResult(boolean isValid, Set<ConstraintViolation<T>> set) {
		this.isValid=isValid;
		this.set=set;
	}

	/**
	 * 查询验证是否通过
	 * @return
	 */
	public boolean isValid() {
		return isValid;
	}

	/**
	 * 获得验证的错误信息
	 * @return
	 */
	public String getMessage(){
		
		if (this.set.size()==0)
			return null;
		
		StringBuilder sb = new StringBuilder();
		
		for(ConstraintViolation<T> cv : set){
			sb.append(cv.getPropertyPath().toString());
			sb.append(":");
			sb.append(cv.getMessage());
			sb.append("   ");
			sb.append("\r\n");
		}
		
		return sb.toString();
		
	}
	

}
